package com.eqdd.yiqidian.widget;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

import com.eqdd.yiqidian.EditDialogActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.utils.KeyboardUtil;

/**
 * Created by lvzhihao on 17-8-4.
 */

public class EditDialogActivity extends BaseActivity {

    private EditDialogActivityCustom dataBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        isKeyBoardJustPan=false;
        setFinishOnTouchOutside(true);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_edit_dialog);
    }

    @Override
    public void initData() {

    }

    @Override
    public void setView() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        (new Handler()).postDelayed(()->{
                InputMethodManager inManager = (InputMethodManager) dataBinding.etContent.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                inManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
            }
        , 500);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (MotionEvent.ACTION_OUTSIDE == event.getAction()) {
            KeyboardUtil.hideSoftInput(this);
            finish();
            return true;
        }
        return super.onTouchEvent(event);
    }
}
